package druid.filter;

import com.alibaba.druid.filter.FilterAdapter;
import com.alibaba.druid.filter.FilterChain;
import com.alibaba.druid.proxy.jdbc.ConnectionProxy;
import com.alibaba.druid.proxy.jdbc.PreparedStatementProxy;
import com.alibaba.druid.proxy.jdbc.ResultSetProxy;
import com.alibaba.druid.proxy.jdbc.StatementProxy;

import java.sql.SQLException;

public class DefFilter extends FilterAdapter {

    public DefFilter() {
    }

    @Override
    public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, String sql) throws SQLException {
        System.out.println("connection_prepareStatement执行前可以解析SQL后修改SQL");
        sql += " -- sql connection_prepareStatement";

        return super.connection_prepareStatement(chain, connection, sql);
    }


    @Override
    public ResultSetProxy preparedStatement_executeQuery(FilterChain chain, PreparedStatementProxy statement) throws SQLException {
        System.out.println("========准备preparedStatement_executeQuery");
        return super.preparedStatement_executeQuery(chain, statement);
    }
    @Override
    public ResultSetProxy statement_executeQuery(FilterChain chain, StatementProxy statement, String sql) throws SQLException {
        System.out.println("statement_executeQuery预处理状态解析sql后执行");
        sql += " -- sql statement_executeQuery";
        return super.statement_executeQuery(chain, statement, sql);
    }

    @Override
    public boolean statement_execute(FilterChain chain, StatementProxy statement, String sql) throws SQLException {
        System.out.println("直接执行sql后执行");
        sql += " -- sql statement_execute";
        return super.statement_execute(chain, statement, sql);
    }


}
